package com.zr.action;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletResponseAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.datamodel.GoodTypeDM;
import com.zr.datamodel.OrderDM;
import com.zr.service.GoodTypeService;
import com.zr.service.OrderService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Controller
@Scope(value = "prototype") // 以多例的方式生成
public class OrderAction extends ActionSupport implements ServletResponseAware{
	private int page;
	private int rows;
	private String status;
	private String senderName;
	private OrderDM orders;
	private int goodTypeId;
	private String GoodTypeName;
	private  HttpServletResponse  resp;
	
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getRows() {
		return rows;
	}
	public void setRows(int rows) {
		this.rows = rows;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getSenderName() {
		return senderName;
	}
	public void setSenderName(String senderName) {
		this.senderName = senderName;
	}
	public OrderDM getOrder() {
		return orders;
	}
	public void setOrder(OrderDM orders) {
		this.orders = orders;
	}

	public int getGoodTypeId() {
		return goodTypeId;
	}
	public void setGoodTypeId(int goodTypeId) {
		this.goodTypeId = goodTypeId;
	}
	public String getGoodTypeName() {
		return GoodTypeName;
	}
	public void setGoodTypeName(String goodTypeName) {
		GoodTypeName = goodTypeName;
	}
	@Resource
	private  OrderService  orderService;
	/**
	 * 查新订单信息
	 * @throws Exception
	 */
	public void showMsg() throws Exception{
		resp.setCharacterEncoding("utf8");
		JSONObject  obj = orderService.findOrderMsg(page, rows,senderName);
		try {
			resp.getWriter().write(obj.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	/**
	 * 显示出货物类别名称
	 */
	public void showGoodType(){
		resp.setCharacterEncoding("utf8");
		JSONArray jArray=orderService.findGoodType();
		try {
			resp.getWriter().write(jArray.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/**
	 * 增加订单信息
	 * @return
	 * @throws Exception
	 */
	public String insertOrderMsg() throws Exception{
		resp.setCharacterEncoding("utf8");
		orderService.insertOrderMsg(orders);
		return SUCCESS;
	}
	/**
	 * 修改订单信息
	 * @throws Exception
	 */
	public void updateOrderMsg() throws Exception{
		
	}
	@Override
	public void setServletResponse(HttpServletResponse response) {
		// TODO Auto-generated method stub
		this.resp=response;
	}
}
